home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / sources / unix / volume24 / rcs / part08 < prev    next >
Encoding:
Internet Message Format  |  1991-03-05  |  53.2 KB

  1. Subject:  v24i008:  RCS source control system, Part08/12
  2. Newsgroups: comp.sources.unix
  3. Approved: rsalz@uunet.UU.NET
  4. X-Checksum-Snefru: 03e33083 44e7b0bc b7f9d611 3c76c722
  5.  
  6. Submitted-by: Adam Hammer <hammer@cs.purdue.edu>
  7. Posting-number: Volume 24, Issue 8
  8. Archive-name: rcs/part08
  9.  
  10. #! /bin/sh
  11. # This is a shell archive.  Remove anything before this line, then feed it
  12. # into a shell via "sh file" or similar.  To overwrite existing files,
  13. # type "sh file -c".
  14. # The tool that generated this appeared in the comp.sources.unix newsgroup;
  15. # send mail to comp-sources-unix@uunet.uu.net if you want that tool.
  16. # Contents:  COPYING src/partime.c src/rcssyn.c
  17. # Wrapped by rsalz@litchi.bbn.com on Thu Feb 21 14:37:04 1991
  18. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  19. echo If this archive is complete, you will see the following message:
  20. echo '          "shar: End of archive 8 (of 12)."'
  21. if test -f 'COPYING' -a "${1}" != "-c" ; then 
  22.   echo shar: Will not clobber existing file \"'COPYING'\"
  23. else
  24.   echo shar: Extracting \"'COPYING'\" \(12488 characters\)
  25.   sed "s/^X//" >'COPYING' <<'END_OF_FILE'
  26. X
  27. X            GNU GENERAL PUBLIC LICENSE
  28. X             Version 1, February 1989
  29. X
  30. X Copyright (C) 1989 Free Software Foundation, Inc.
  31. X                    675 Mass Ave, Cambridge, MA 02139, USA
  32. X Everyone is permitted to copy and distribute verbatim copies
  33. X of this license document, but changing it is not allowed.
  34. X
  35. X                Preamble
  36. X
  37. X  The license agreements of most software companies try to keep users
  38. Xat the mercy of those companies.  By contrast, our General Public
  39. XLicense is intended to guarantee your freedom to share and change free
  40. Xsoftware--to make sure the software is free for all its users.  The
  41. XGeneral Public License applies to the Free Software Foundation's
  42. Xsoftware and to any other program whose authors commit to using it.
  43. XYou can use it for your programs, too.
  44. X
  45. X  When we speak of free software, we are referring to freedom, not
  46. Xprice.  Specifically, the General Public License is designed to make
  47. Xsure that you have the freedom to give away or sell copies of free
  48. Xsoftware, that you receive source code or can get it if you want it,
  49. Xthat you can change the software or use pieces of it in new free
  50. Xprograms; and that you know you can do these things.
  51. X
  52. X  To protect your rights, we need to make restrictions that forbid
  53. Xanyone to deny you these rights or to ask you to surrender the rights.
  54. XThese restrictions translate to certain responsibilities for you if you
  55. Xdistribute copies of the software, or if you modify it.
  56. X
  57. X  For example, if you distribute copies of a such a program, whether
  58. Xgratis or for a fee, you must give the recipients all the rights that
  59. Xyou have.  You must make sure that they, too, receive or can get the
  60. Xsource code.  And you must tell them their rights.
  61. X
  62. X  We protect your rights with two steps: (1) copyright the software, and
  63. X(2) offer you this license which gives you legal permission to copy,
  64. Xdistribute and/or modify the software.
  65. X
  66. X  Also, for each author's protection and ours, we want to make certain
  67. Xthat everyone understands that there is no warranty for this free
  68. Xsoftware.  If the software is modified by someone else and passed on, we
  69. Xwant its recipients to know that what they have is not the original, so
  70. Xthat any problems introduced by others will not reflect on the original
  71. Xauthors' reputations.
  72. X
  73. X  The precise terms and conditions for copying, distribution and
  74. Xmodification follow.
  75. X
  76. X            GNU GENERAL PUBLIC LICENSE
  77. X   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
  78. X
  79. X  0. This License Agreement applies to any program or other work which
  80. Xcontains a notice placed by the copyright holder saying it may be
  81. Xdistributed under the terms of this General Public License.  The
  82. X"Program", below, refers to any such program or work, and a "work based
  83. Xon the Program" means either the Program or any work containing the
  84. XProgram or a portion of it, either verbatim or with modifications.  Each
  85. Xlicensee is addressed as "you".
  86. X
  87. X  1. You may copy and distribute verbatim copies of the Program's source
  88. Xcode as you receive it, in any medium, provided that you conspicuously and
  89. Xappropriately publish on each copy an appropriate copyright notice and
  90. Xdisclaimer of warranty; keep intact all the notices that refer to this
  91. XGeneral Public License and to the absence of any warranty; and give any
  92. Xother recipients of the Program a copy of this General Public License
  93. Xalong with the Program.  You may charge a fee for the physical act of
  94. Xtransferring a copy.
  95. X
  96. X  2. You may modify your copy or copies of the Program or any portion of
  97. Xit, and copy and distribute such modifications under the terms of Paragraph
  98. X1 above, provided that you also do the following:
  99. X
  100. X    a) cause the modified files to carry prominent notices stating that
  101. X    you changed the files and the date of any change; and
  102. X
  103. X    b) cause the whole of any work that you distribute or publish, that
  104. X    in whole or in part contains the Program or any part thereof, either
  105. X    with or without modifications, to be licensed at no charge to all
  106. X    third parties under the terms of this General Public License (except
  107. X    that you may choose to grant warranty protection to some or all
  108. X    third parties, at your option).
  109. X
  110. X    c) If the modified program normally reads commands interactively when
  111. X    run, you must cause it, when started running for such interactive use
  112. X    in the simplest and most usual way, to print or display an
  113. X    announcement including an appropriate copyright notice and a notice
  114. X    that there is no warranty (or else, saying that you provide a
  115. X    warranty) and that users may redistribute the program under these
  116. X    conditions, and telling the user how to view a copy of this General
  117. X    Public License.
  118. X
  119. X    d) You may charge a fee for the physical act of transferring a
  120. X    copy, and you may at your option offer warranty protection in
  121. X    exchange for a fee.
  122. X
  123. XMere aggregation of another independent work with the Program (or its
  124. Xderivative) on a volume of a storage or distribution medium does not bring
  125. Xthe other work under the scope of these terms.
  126. X
  127. X  3. You may copy and distribute the Program (or a portion or derivative of
  128. Xit, under Paragraph 2) in object code or executable form under the terms of
  129. XParagraphs 1 and 2 above provided that you also do one of the following:
  130. X
  131. X    a) accompany it with the complete corresponding machine-readable
  132. X    source code, which must be distributed under the terms of
  133. X    Paragraphs 1 and 2 above; or,
  134. X
  135. X    b) accompany it with a written offer, valid for at least three
  136. X    years, to give any third party free (except for a nominal charge
  137. X    for the cost of distribution) a complete machine-readable copy of the
  138. X    corresponding source code, to be distributed under the terms of
  139. X    Paragraphs 1 and 2 above; or,
  140. X
  141. X    c) accompany it with the information you received as to where the
  142. X    corresponding source code may be obtained.  (This alternative is
  143. X    allowed only for noncommercial distribution and only if you
  144. X    received the program in object code or executable form alone.)
  145. X
  146. XSource code for a work means the preferred form of the work for making
  147. Xmodifications to it.  For an executable file, complete source code means
  148. Xall the source code for all modules it contains; but, as a special
  149. Xexception, it need not include source code for modules which are standard
  150. Xlibraries that accompany the operating system on which the executable
  151. Xfile runs, or for standard header files or definitions files that
  152. Xaccompany that operating system.
  153. X
  154. X  4. You may not copy, modify, sublicense, distribute or transfer the
  155. XProgram except as expressly provided under this General Public License.
  156. XAny attempt otherwise to copy, modify, sublicense, distribute or transfer
  157. Xthe Program is void, and will automatically terminate your rights to use
  158. Xthe Program under this License.  However, parties who have received
  159. Xcopies, or rights to use copies, from you under this General Public
  160. XLicense will not have their licenses terminated so long as such parties
  161. Xremain in full compliance.
  162. X
  163. X  5. By copying, distributing or modifying the Program (or any work based
  164. Xon the Program) you indicate your acceptance of this license to do so,
  165. Xand all its terms and conditions.
  166. X
  167. X  6. Each time you redistribute the Program (or any work based on the
  168. XProgram), the recipient automatically receives a license from the original
  169. Xlicensor to copy, distribute or modify the Program subject to these
  170. Xterms and conditions.  You may not impose any further restrictions on the
  171. Xrecipients' exercise of the rights granted herein.
  172. X
  173. X  7. The Free Software Foundation may publish revised and/or new versions
  174. Xof the General Public License from time to time.  Such new versions will
  175. Xbe similar in spirit to the present version, but may differ in detail to
  176. Xaddress new problems or concerns.
  177. X
  178. XEach version is given a distinguishing version number.  If the Program
  179. Xspecifies a version number of the license which applies to it and "any
  180. Xlater version", you have the option of following the terms and conditions
  181. Xeither of that version or of any later version published by the Free
  182. XSoftware Foundation.  If the Program does not specify a version number of
  183. Xthe license, you may choose any version ever published by the Free Software
  184. XFoundation.
  185. X
  186. X  8. If you wish to incorporate parts of the Program into other free
  187. Xprograms whose distribution conditions are different, write to the author
  188. Xto ask for permission.  For software which is copyrighted by the Free
  189. XSoftware Foundation, write to the Free Software Foundation; we sometimes
  190. Xmake exceptions for this.  Our decision will be guided by the two goals
  191. Xof preserving the free status of all derivatives of our free software and
  192. Xof promoting the sharing and reuse of software generally.
  193. X
  194. X                NO WARRANTY
  195. X
  196. X  9. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
  197. XFOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW.  EXCEPT WHEN
  198. XOTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
  199. XPROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
  200. XOR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  201. XMERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE RISK AS
  202. XTO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU.  SHOULD THE
  203. XPROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
  204. XREPAIR OR CORRECTION.
  205. X
  206. X  10. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
  207. XWILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
  208. XREDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
  209. XINCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
  210. XOUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
  211. XTO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
  212. XYOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
  213. XPROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
  214. XPOSSIBILITY OF SUCH DAMAGES.
  215. X
  216. X             END OF TERMS AND CONDITIONS
  217. X
  218. X    Appendix: How to Apply These Terms to Your New Programs
  219. X
  220. X  If you develop a new program, and you want it to be of the greatest
  221. Xpossible use to humanity, the best way to achieve this is to make it
  222. Xfree software which everyone can redistribute and change under these
  223. Xterms.
  224. X
  225. X  To do so, attach the following notices to the program.  It is safest to
  226. Xattach them to the start of each source file to most effectively convey
  227. Xthe exclusion of warranty; and each file should have at least the
  228. X"copyright" line and a pointer to where the full notice is found.
  229. X
  230. X    <one line to give the program's name and a brief idea of what it does.>
  231. X    Copyright (C) 19yy  <name of author>
  232. X
  233. X    This program is free software; you can redistribute it and/or modify
  234. X    it under the terms of the GNU General Public License as published by
  235. X    the Free Software Foundation; either version 1, or (at your option)
  236. X    any later version.
  237. X
  238. X    This program is distributed in the hope that it will be useful,
  239. X    but WITHOUT ANY WARRANTY; without even the implied warranty of
  240. X    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  241. X    GNU General Public License for more details.
  242. X
  243. X    You should have received a copy of the GNU General Public License
  244. X    along with this program; if not, write to the Free Software
  245. X    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  246. X
  247. XAlso add information on how to contact you by electronic and paper mail.
  248. X
  249. XIf the program is interactive, make it output a short notice like this
  250. Xwhen it starts in an interactive mode:
  251. X
  252. X    Gnomovision version 69, Copyright (C) 19xx name of author
  253. X    Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
  254. X    This is free software, and you are welcome to redistribute it
  255. X    under certain conditions; type `show c' for details.
  256. X
  257. XThe hypothetical commands `show w' and `show c' should show the
  258. Xappropriate parts of the General Public License.  Of course, the
  259. Xcommands you use may be called something other than `show w' and `show
  260. Xc'; they could even be mouse-clicks or menu items--whatever suits your
  261. Xprogram.
  262. X
  263. XYou should also get your employer (if you work as a programmer) or your
  264. Xschool, if any, to sign a "copyright disclaimer" for the program, if
  265. Xnecessary.  Here a sample; alter the names:
  266. X
  267. X  Yoyodyne, Inc., hereby disclaims all copyright interest in the
  268. X  program `Gnomovision' (a program to direct compilers to make passes
  269. X  at assemblers) written by James Hacker.
  270. X
  271. X  <signature of Ty Coon>, 1 April 1989
  272. X  Ty Coon, President of Vice
  273. X
  274. XThat's all there is to it!
  275. END_OF_FILE
  276.   if test 12488 -ne `wc -c <'COPYING'`; then
  277.     echo shar: \"'COPYING'\" unpacked with wrong size!
  278.   fi
  279.   # end of 'COPYING'
  280. fi
  281. if test -f 'src/partime.c' -a "${1}" != "-c" ; then 
  282.   echo shar: Will not clobber existing file \"'src/partime.c'\"
  283. else
  284.   echo shar: Extracting \"'src/partime.c'\" \(19500 characters\)
  285.   sed "s/^X//" >'src/partime.c' <<'END_OF_FILE'
  286. X/*
  287. X * PARTIME        parse date/time string into a TM structure
  288. X *
  289. X * Returns:
  290. X *    0 if parsing failed
  291. X *    else time values in specified TM structure and zone (unspecified values
  292. X *        set to TMNULL)
  293. X * Notes:
  294. X *    This code is quasi-public; it may be used freely in like software.
  295. X *    It is not to be sold, nor used in licensed software without
  296. X *    permission of the author.
  297. X *    For everyone's benefit, please report bugs and improvements!
  298. X *     Copyright 1980 by Ken Harrenstien, SRI International.
  299. X *    (ARPANET: KLH @ SRI)
  300. X */
  301. X
  302. X/* Hacknotes:
  303. X *    If parsing changed so that no backup needed, could perhaps modify
  304. X *        to use a FILE input stream.  Need terminator, though.
  305. X *    Perhaps should return 0 on success, else a non-zero error val?
  306. X */
  307. X
  308. X/* $Log: partime.c,v $
  309. X * Revision 5.4  1990/10/04  06:30:15  eggert
  310. X * Remove date vs time heuristics that fail between 2000 and 2400.
  311. X * Check for overflow when lexing an integer.
  312. X * Parse 'Jan 10 LT' as 'Jan 10, LT', not 'Jan, 10 LT'.
  313. X *
  314. X * Revision 5.3  1990/09/24  18:56:31  eggert
  315. X * Update timezones.
  316. X *
  317. X * Revision 5.2  1990/09/04  08:02:16  eggert
  318. X * Don't parse two-digit years, because it won't work after 1999/12/31.
  319. X * Don't permit 'Aug Aug'.
  320. X *
  321. X * Revision 5.1  1990/08/29  07:13:49  eggert
  322. X * Be able to parse our own date format.  Don't assume year<10000.
  323. X *
  324. X * Revision 5.0  1990/08/22  08:12:40  eggert
  325. X * Switch to GMT and fix the bugs exposed thereby.  Update timezones.
  326. X * Ansify and Posixate.  Fix peekahead and int-size bugs.
  327. X *
  328. X * Revision 1.4  89/05/01  14:48:46  narten
  329. X * fixed #ifdef DEBUG construct
  330. X * 
  331. X * Revision 1.3  88/08/28  14:53:40  eggert
  332. X * Remove unportable "#endif XXX"s.
  333. X * 
  334. X * Revision 1.2  87/03/27  14:21:53  jenkins
  335. X * Port to suns
  336. X * 
  337. X * Revision 1.1  82/05/06  11:38:26  wft
  338. X * Initial revision
  339. X * 
  340. X */
  341. X
  342. X#include "rcsbase.h"
  343. X
  344. XlibId(partId, "$Id: partime.c,v 5.4 1990/10/04 06:30:15 eggert Exp $")
  345. X
  346. X#define given(v) (0 <= (v))
  347. X#define TMNULL (-1) /* Items not given are given this value */
  348. X#define TZ_OFFSET (24*60) /* TMNULL  <  zone_offset - TZ_OFFSET */
  349. X
  350. Xstruct tmwent {
  351. X    const char *went;
  352. X    short wval;
  353. X    char wflgs;
  354. X    char wtype;
  355. X};
  356. X    /* wflgs */
  357. X#define TWTIME 02    /* Word is a time value (absence implies date) */
  358. X#define TWDST  04    /* Word is a DST-type timezone */
  359. X    /* wtype */
  360. X#define TM_MON    1    /* month name */
  361. X#define TM_WDAY    2    /* weekday name */
  362. X#define TM_ZON    3    /* time zone name */
  363. X#define TM_LT    4    /* local time */
  364. X#define TM_DST    5    /* daylight savings time */
  365. X#define TM_12    6    /* AM, PM, NOON, or MIDNIGHT */
  366. X    /* wval (for wtype==TM_12) */
  367. X#define T12_AM 1
  368. X#define T12_PM 2
  369. X#define T12_NOON 12
  370. X#define T12_MIDNIGHT 0
  371. X
  372. Xstatic const struct tmwent tmwords [] = {
  373. X    {"january",      0, 0, TM_MON},
  374. X    {"february",     1, 0, TM_MON},
  375. X    {"march",        2, 0, TM_MON},
  376. X    {"april",        3, 0, TM_MON},
  377. X    {"may",          4, 0, TM_MON},
  378. X    {"june",         5, 0, TM_MON},
  379. X    {"july",         6, 0, TM_MON},
  380. X    {"august",       7, 0, TM_MON},
  381. X    {"september",    8, 0, TM_MON},
  382. X    {"october",      9, 0, TM_MON},
  383. X    {"november",     10, 0, TM_MON},
  384. X    {"december",     11, 0, TM_MON},
  385. X
  386. X    {"sunday",       0, 0, TM_WDAY},
  387. X    {"monday",       1, 0, TM_WDAY},
  388. X    {"tuesday",      2, 0, TM_WDAY},
  389. X    {"wednesday",    3, 0, TM_WDAY},
  390. X    {"thursday",     4, 0, TM_WDAY},
  391. X    {"friday",       5, 0, TM_WDAY},
  392. X    {"saturday",     6, 0, TM_WDAY},
  393. X
  394. X    {"gmt",          0*60, TWTIME, TM_ZON},   /* Greenwich */
  395. X    {"utc",          0*60, TWTIME, TM_ZON},
  396. X    {"ut",           0*60, TWTIME, TM_ZON},
  397. X
  398. X    {"nzst",        -12*60, TWTIME, TM_ZON},  /* New Zealand */
  399. X    {"jst",         -9*60, TWTIME, TM_ZON},   /* Japan */
  400. X    {"kst",         -9*60, TWTIME, TM_ZON},   /* Korea */
  401. X    {"ist",         -5*60-30, TWTIME, TM_ZON},/* India */
  402. X    {"eet",         -2*60, TWTIME, TM_ZON},   /* Eastern Europe */
  403. X    {"cet",         -1*60, TWTIME, TM_ZON},   /* Central Europe */
  404. X    {"met",         -1*60, TWTIME, TM_ZON},   /* Middle Europe */
  405. X    {"wet",          0*60, TWTIME, TM_ZON},   /* Western Europe */
  406. X    {"nst",          3*60+30, TWTIME, TM_ZON},/* Newfoundland */
  407. X    {"ast",          4*60, TWTIME, TM_ZON},   /* Atlantic */
  408. X    {"est",          5*60, TWTIME, TM_ZON},   /* Eastern */
  409. X    {"cst",          6*60, TWTIME, TM_ZON},   /* Central */
  410. X    {"mst",          7*60, TWTIME, TM_ZON},   /* Mountain */
  411. X    {"pst",          8*60, TWTIME, TM_ZON},   /* Pacific */
  412. X    {"akst",         9*60, TWTIME, TM_ZON},   /* Alaska */
  413. X    {"hast",         10*60, TWTIME, TM_ZON},  /* Hawaii-Aleutian */
  414. X    {"hst",          10*60, TWTIME, TM_ZON},  /* Hawaii */
  415. X    {"sst",          11*60, TWTIME, TM_ZON},  /* Samoa */
  416. X
  417. X    {"nzdt",        -12*60, TWTIME+TWDST, TM_ZON},    /* New Zealand */
  418. X    {"kdt",         -9*60, TWTIME+TWDST, TM_ZON},     /* Korea */
  419. X    {"bst",          0*60, TWTIME+TWDST, TM_ZON},     /* Britain */
  420. X    {"ndt",          2*60+30, TWTIME+TWDST, TM_ZON}, /*Newfoundland (DDST)*/
  421. X    {"adt",          4*60, TWTIME+TWDST, TM_ZON},     /* Atlantic */
  422. X    {"edt",          5*60, TWTIME+TWDST, TM_ZON},     /* Eastern */
  423. X    {"cdt",          6*60, TWTIME+TWDST, TM_ZON},     /* Central */
  424. X    {"mdt",          7*60, TWTIME+TWDST, TM_ZON},     /* Mountain */
  425. X    {"pdt",          8*60, TWTIME+TWDST, TM_ZON},     /* Pacific */
  426. X    {"akdt",         9*60, TWTIME+TWDST, TM_ZON},     /* Alaska */
  427. X    {"hadt",         10*60, TWTIME+TWDST, TM_ZON},    /* Hawaii-Aleutian */
  428. X
  429. X#if 0
  430. X    /*
  431. X     * The following names are duplicates or are not well attested.
  432. X     * A standard is needed.
  433. X     */
  434. X    {"?st",         -13*60, TWTIME, TM_ZON},  /* Uelen */
  435. X    {"?st",         -11*60, TWTIME, TM_ZON},  /* Magadan */
  436. X    {"east",        -10*60, TWTIME, TM_ZON},  /* Eastern Australia */
  437. X    {"cast",        -9*60-30, TWTIME, TM_ZON},/* Central Australia */
  438. X    {"cst",         -8*60, TWTIME, TM_ZON},   /* China */
  439. X    {"hkt",         -8*60, TWTIME, TM_ZON},   /* Hong Kong */
  440. X    {"sst",         -8*60, TWTIME, TM_ZON},   /* Singapore */
  441. X    {"wast",        -8*60, TWTIME, TM_ZON},   /* Western Australia */
  442. X    {"?st",         -7*60, TWTIME, TM_ZON},   /* Novosibirsk */
  443. X    {"jt",          -7*60-30, TWTIME, TM_ZON},/* Java */
  444. X    {"nst",         -6*60-30, TWTIME, TM_ZON},/* North Sumatra */
  445. X    {"?st",         -6*60, TWTIME, TM_ZON},   /* Tashkent */
  446. X    {"?st",         -5*60, TWTIME, TM_ZON},      /* Sverdlovsk */
  447. X    {"?",           -4*60-30, TWTIME, TM_ZON},/* Afghanistan */
  448. X    {"?st",         -4*60, TWTIME, TM_ZON},      /* Rostov */
  449. X    {"it",          -3*60-30, TWTIME, TM_ZON},/* Iran */
  450. X    {"?st",         -3*60, TWTIME, TM_ZON},   /* Moscow */
  451. X    {"ist",         -2*60, TWTIME, TM_ZON},   /* Israel */
  452. X    {"ast",          1*60, TWTIME, TM_ZON},   /* Azores */
  453. X    {"fst",          2*60, TWTIME, TM_ZON},   /* Fernando de Noronha */
  454. X    {"bst",          3*60, TWTIME, TM_ZON},   /* Brazil */
  455. X    {"wst",          4*60, TWTIME, TM_ZON},   /* Western Brazil */
  456. X    {"ast",          5*60, TWTIME, TM_ZON},   /* Acre Brazil */
  457. X    {"?",            9*60+30, TWTIME, TM_ZON},/* Marquesas */
  458. X    {"?st",          12*60, TWTIME, TM_ZON},  /* Kwajalein */
  459. X
  460. X    {"?dt",         -13*60, TWTIME+TWDST, TM_ZON},      /* Uelen */
  461. X    {"?dt",         -11*60, TWTIME+TWDST, TM_ZON},      /* Magadan */
  462. X    {"eadt",        -10*60, TWTIME+TWDST, TM_ZON},    /* Eastern Australia */
  463. X    {"cadt",        -9*60-30, TWTIME+TWDST, TM_ZON},  /* Central Australia */
  464. X    {"cdt",         -8*60, TWTIME+TWDST, TM_ZON},     /* China */
  465. X    {"wadt",        -8*60, TWTIME+TWDST, TM_ZON},     /* Western Australia */
  466. X    {"?dt",         -7*60, TWTIME+TWDST, TM_ZON},      /* Novosibirsk */
  467. X    {"?dt",         -6*60, TWTIME+TWDST, TM_ZON},      /* Tashkent */
  468. X    {"?dt",         -5*60, TWTIME+TWDST, TM_ZON},      /* Sverdlovsk */
  469. X    {"?dt",         -4*60, TWTIME+TWDST, TM_ZON},      /* Rostov */
  470. X    {"?dt",         -3*60, TWTIME+TWDST, TM_ZON},     /* Moscow */
  471. X    {"idt",         -2*60, TWTIME+TWDST, TM_ZON},     /* Israel */
  472. X    {"eest",        -2*60, TWTIME+TWDST, TM_ZON},     /* Eastern Europe */
  473. X    {"cest",        -1*60, TWTIME+TWDST, TM_ZON},     /* Central Europe */
  474. X    {"mest",        -1*60, TWTIME+TWDST, TM_ZON},     /* Middle Europe */
  475. X    {"west",         0*60, TWTIME+TWDST, TM_ZON},     /* Western Europe */
  476. X    {"adt",          1*60, TWTIME+TWDST, TM_ZON},      /* Azores */
  477. X    {"fdt",          2*60, TWTIME+TWDST, TM_ZON},     /* Fernando de Noronha */
  478. X    {"edt",          3*60, TWTIME+TWDST, TM_ZON},     /* Eastern Brazil */
  479. X    {"wdt",          4*60, TWTIME+TWDST, TM_ZON},     /* Western Brazil */
  480. X    {"adt",          5*60, TWTIME+TWDST, TM_ZON},     /* Acre Brazil */
  481. X#endif
  482. X
  483. X    {"lt",           0, TWTIME, TM_LT},       /* local time */
  484. X    {"dst",          1*60, TWTIME, TM_DST},      /* daylight savings time */
  485. X    {"ddst",         2*60, TWTIME, TM_DST},      /* double dst */
  486. X
  487. X    {"am",           T12_AM,    TWTIME, TM_12},
  488. X    {"pm",           T12_PM,    TWTIME, TM_12},
  489. X    {"noon",         T12_NOON,    TWTIME, TM_12},
  490. X    {"midnight",     T12_MIDNIGHT,    TWTIME, TM_12},
  491. X
  492. X    {0, 0, 0, 0},             /* Zero entry to terminate searches */
  493. X};
  494. X
  495. Xstruct token {
  496. X    const char *tcp;/* pointer to string */
  497. X    int tcnt;    /* # chars */
  498. X    char tbrk;    /* "break" char */
  499. X    char tbrkl;    /* last break char */
  500. X    char tflg;    /* 0 = alpha, 1 = numeric */
  501. X    union {         /* Resulting value; */
  502. X        int tnum;/* either a #, or */
  503. X        const struct tmwent *ttmw;/* ptr to a tmwent. */
  504. X    } tval;
  505. X};
  506. X
  507. Xstatic const struct tmwent*ptmatchstr P((const char*,int,const struct tmwent*));
  508. Xstatic int pt12hack P((struct tm *,int));
  509. Xstatic int ptitoken P((struct token *));
  510. Xstatic int ptstash P((int *,int));
  511. Xstatic int pttoken P((struct token *));
  512. X
  513. X    static int
  514. Xgoodzone(t, offset, am)
  515. X    register const struct token *t;
  516. X    int offset;
  517. X    int *am;
  518. X{
  519. X    register int m;
  520. X    if (
  521. X        t->tflg  &&
  522. X        t->tcnt == 4+offset  &&
  523. X        (m = t->tval.tnum) <= 2400  &&
  524. X        isdigit(t->tcp[offset]) &&
  525. X        (m%=100) < 60
  526. X    ) {
  527. X        m += t->tval.tnum/100 * 60;
  528. X        if (t->tcp[offset-1]=='+')
  529. X            m = -m;
  530. X        *am = m;
  531. X        return 1;
  532. X    }
  533. X    return 0;
  534. X}
  535. X
  536. X    int
  537. Xpartime(astr, atm, zone)
  538. Xconst char *astr;
  539. Xregister struct tm *atm;
  540. Xint *zone;
  541. X{
  542. X    register int i;
  543. X    struct token btoken, atoken;
  544. X    int zone_offset; /* minutes west of GMT, plus TZ_OFFSET */
  545. X    register const char *cp;
  546. X    register char ch;
  547. X    int ord, midnoon;
  548. X    int *atmfield, dst, m;
  549. X    int got1 = 0;
  550. X
  551. X    atm->tm_sec = TMNULL;
  552. X    atm->tm_min = TMNULL;
  553. X    atm->tm_hour = TMNULL;
  554. X    atm->tm_mday = TMNULL;
  555. X    atm->tm_mon = TMNULL;
  556. X    atm->tm_year = TMNULL;
  557. X    atm->tm_wday = TMNULL;
  558. X    atm->tm_yday = TMNULL;
  559. X    midnoon = TMNULL;        /* and our own temp stuff */
  560. X    zone_offset = TMNULL;
  561. X    dst = TMNULL;
  562. X    btoken.tcnt = btoken.tbrk = 0;
  563. X    btoken.tcp = astr;
  564. X
  565. X    for (;; got1=1) {
  566. X    if (!ptitoken(&btoken))                /* Get a token */
  567. X      {     if(btoken.tval.tnum) return(0);         /* Read error? */
  568. X        if (given(midnoon))            /* EOF, wrap up */
  569. X            if (!pt12hack(atm, midnoon))
  570. X                return 0;
  571. X        if (!given(atm->tm_min))
  572. X            atm->tm_min = 0;
  573. X        *zone  =
  574. X                (given(zone_offset) ? zone_offset-TZ_OFFSET : 0)
  575. X            -    (given(dst) ? dst : 0);
  576. X        return got1;
  577. X      }
  578. X    if(btoken.tflg == 0)        /* Alpha? */
  579. X      {     i = btoken.tval.ttmw->wval;
  580. X        switch (btoken.tval.ttmw->wtype) {
  581. X          default:
  582. X            return 0;
  583. X          case TM_MON:
  584. X            atmfield = &atm->tm_mon;
  585. X            break;
  586. X          case TM_WDAY:
  587. X            atmfield = &atm->tm_wday;
  588. X            break;
  589. X          case TM_DST:
  590. X            atmfield = &dst;
  591. X            break;
  592. X          case TM_LT:
  593. X            if (ptstash(&dst, 0))
  594. X                return 0;
  595. X            i = 48*60; /* local time magic number -- see maketime() */
  596. X            /* fall into */
  597. X          case TM_ZON:
  598. X            i += TZ_OFFSET;
  599. X            if (btoken.tval.ttmw->wflgs & TWDST)
  600. X                if (ptstash(&dst, 60))
  601. X                    return 0;
  602. X            /* Peek ahead for offset immediately afterwards. */
  603. X            if (
  604. X                (btoken.tbrk=='-' || btoken.tbrk=='+') &&
  605. X                (atoken=btoken, ++atoken.tcnt, ptitoken(&atoken)) &&
  606. X                goodzone(&atoken, 0, &m)
  607. X            ) {
  608. X                i += m;
  609. X                btoken = atoken;
  610. X            }
  611. X            atmfield = &zone_offset;
  612. X            break;
  613. X          case TM_12:
  614. X            atmfield = &midnoon;
  615. X        }
  616. X        if (ptstash(atmfield, i))
  617. X            return(0);        /* ERR: val already set */
  618. X        continue;
  619. X      }
  620. X
  621. X    /* Token is number.  Lots of hairy heuristics. */
  622. X    if (!isdigit(*btoken.tcp)) {
  623. X        if (!goodzone(&btoken, 1, &m))
  624. X            return 0;
  625. X        zone_offset = TZ_OFFSET + m;
  626. X        continue;
  627. X    }
  628. X
  629. X    i = btoken.tval.tnum;   /* Value now known to be valid; get it. */
  630. X    if (btoken.tcnt == 3)    /*  3 digits = HMM   */
  631. X      {
  632. Xhhmm4:        if (ptstash(&atm->tm_min, i%100))
  633. X            return(0);        /* ERR: min conflict */
  634. X        i /= 100;
  635. Xhh2:            if (ptstash(&atm->tm_hour, i))
  636. X            return(0);        /* ERR: hour conflict */
  637. X        continue;
  638. X      }
  639. X
  640. X    if (4 < btoken.tcnt)
  641. X        goto year4; /* far in the future */
  642. X    if(btoken.tcnt == 4)    /* 4 digits = YEAR or HHMM */
  643. X      {    if (given(atm->tm_year)) goto hhmm4;    /* Already got yr? */
  644. X        if (given(atm->tm_hour)) goto year4;    /* Already got hr? */
  645. X        if(btoken.tbrk == ':')            /* HHMM:SS ? */
  646. X            if ( ptstash(&atm->tm_hour, i/100)
  647. X              || ptstash(&atm->tm_min, i%100))
  648. X                return(0);        /* ERR: hr/min clash */
  649. X            else goto coltm2;        /* Go handle SS */
  650. X        if(btoken.tbrk != ',' && btoken.tbrk != '/'
  651. X          && (atoken=btoken, ptitoken(&atoken))    /* Peek */
  652. X          && ( atoken.tflg
  653. X             ? !isdigit(*atoken.tcp)
  654. X             : atoken.tval.ttmw->wflgs & TWTIME)) /* HHMM-ZON */
  655. X            goto hhmm4;
  656. X        goto year4;            /* Give up, assume year. */
  657. X      }
  658. X
  659. X    /* From this point on, assume tcnt == 1 or 2 */
  660. X    /* 2 digits = MM, DD, or HH (MM and SS caught at coltime) */
  661. X    if(btoken.tbrk == ':')        /* HH:MM[:SS] */
  662. X        goto coltime;        /*  must be part of time. */
  663. X    if (31 < i)
  664. X        return 0;
  665. X
  666. X    /* Check for numerical-format date */
  667. X    for (cp = "/-."; ch = *cp++;)
  668. X      {    ord = (ch == '.' ? 0 : 1);    /* n/m = D/M or M/D */
  669. X        if(btoken.tbrk == ch)            /* "NN-" */
  670. X          {    if(btoken.tbrkl != ch)
  671. X              {
  672. X                atoken = btoken;
  673. X                atoken.tcnt++;
  674. X                if (ptitoken(&atoken)
  675. X                  && atoken.tflg == 0
  676. X                  && atoken.tval.ttmw->wtype == TM_MON)
  677. X                    goto dd2;
  678. X                if(ord)goto mm2; else goto dd2; /* "NN-" */
  679. X              }                /* "-NN-" */
  680. X            if (!given(atm->tm_mday)
  681. X              && given(atm->tm_year))    /* If "YYYY-NN-" */
  682. X                goto mm2;        /* then always MM */
  683. X            if(ord)goto dd2; else goto mm2;
  684. X          }
  685. X        if(btoken.tbrkl == ch            /* "-NN" */
  686. X          && given(ord ? atm->tm_mon : atm->tm_mday))
  687. X            if (!given(ord ? atm->tm_mday : atm->tm_mon)) /* MM/DD */
  688. X                if(ord)goto dd2; else goto mm2;
  689. X      }
  690. X
  691. X    /* Now reduced to choice between HH and DD */
  692. X    if (given(atm->tm_hour)) goto dd2;    /* Have hour? Assume day. */
  693. X    if (given(atm->tm_mday)) goto hh2;    /* Have day? Assume hour. */
  694. X    if (given(atm->tm_mon)) goto dd2;    /* Have month? Assume day. */
  695. X    if(i > 24) goto dd2;            /* Impossible HH means DD */
  696. X    atoken = btoken;
  697. X    if (!ptitoken(&atoken))            /* Read ahead! */
  698. X        if(atoken.tval.tnum) return(0); /* ERR: bad token */
  699. X        else goto dd2;            /* EOF, assume day. */
  700. X    if ( atoken.tflg
  701. X       ? !isdigit(*atoken.tcp)
  702. X       : atoken.tval.ttmw->wflgs & TWTIME)
  703. X        /* If next token is a time spec, assume hour */
  704. X        goto hh2;        /* e.g. "3 PM", "11-EDT"  */
  705. X
  706. Xdd2:    if (ptstash(&atm->tm_mday, i))    /* Store day (1 based) */
  707. X        return(0);
  708. X    continue;
  709. X
  710. Xmm2:    if (ptstash(&atm->tm_mon, i-1))    /* Store month (make zero based) */
  711. X        return(0);
  712. X    continue;
  713. X
  714. Xyear4:    if ((i-=1900) < 0  ||  ptstash(&atm->tm_year, i)) /* Store year-1900 */
  715. X        return(0);        /* ERR: year conflict */
  716. X    continue;
  717. X
  718. X    /* Hack HH:MM[[:]SS] */
  719. Xcoltime:
  720. X    if (ptstash(&atm->tm_hour, i)) return 0;
  721. X    if (!ptitoken(&btoken))
  722. X        return(!btoken.tval.tnum);
  723. X    if(!btoken.tflg) return(0);    /* ERR: HH:<alpha> */
  724. X    if(btoken.tcnt == 4)        /* MMSS */
  725. X        if (ptstash(&atm->tm_min, btoken.tval.tnum/100)
  726. X          || ptstash(&atm->tm_sec, btoken.tval.tnum%100))
  727. X            return(0);
  728. X        else continue;
  729. X    if(btoken.tcnt != 2
  730. X      || ptstash(&atm->tm_min, btoken.tval.tnum))
  731. X        return(0);        /* ERR: MM bad */
  732. X    if (btoken.tbrk != ':') continue;    /* Seconds follow? */
  733. Xcoltm2:    if (!ptitoken(&btoken))
  734. X        return(!btoken.tval.tnum);
  735. X    if(!btoken.tflg || btoken.tcnt != 2    /* Verify SS */
  736. X      || ptstash(&atm->tm_sec, btoken.tval.tnum))
  737. X        return(0);        /* ERR: SS bad */
  738. X    }
  739. X}
  740. X
  741. X/* Store date/time value, return 0 if successful.
  742. X * Fail if entry is already set.
  743. X */
  744. X    static int
  745. Xptstash(adr,val)
  746. Xint *adr;
  747. Xint val;
  748. X{    register int *a;
  749. X    if (given(*(a=adr)))
  750. X        return 1;
  751. X    *a = val;
  752. X    return(0);
  753. X}
  754. X
  755. X/* This subroutine is invoked for AM, PM, NOON and MIDNIGHT when wrapping up
  756. X * just prior to returning from partime.
  757. X */
  758. X    static int
  759. Xpt12hack(tm, aval)
  760. Xregister struct tm *tm;
  761. Xregister int aval;
  762. X{    register int h = tm->tm_hour;
  763. X    switch (aval) {
  764. X      case T12_AM:
  765. X      case T12_PM:
  766. X        if (h > 12)
  767. X            return 0;
  768. X        if (h == 12)
  769. X            tm->tm_hour = 0;
  770. X        if (aval == T12_PM)
  771. X            tm->tm_hour += 12;
  772. X        break;
  773. X      default:
  774. X        if (0 < tm->tm_min  ||  0 < tm->tm_sec)
  775. X            return 0;
  776. X        if (!given(h) || h==12)
  777. X            tm->tm_hour = aval;
  778. X        else if (aval==T12_MIDNIGHT  &&  (h==0 || h==24))
  779. X            return 0;
  780. X    }
  781. X    return 1;
  782. X}
  783. X
  784. X/* Get a token and identify it to some degree.
  785. X * Returns 0 on failure; token.tval will be 0 for normal EOF, otherwise
  786. X * hit error of some sort
  787. X */
  788. X
  789. X    static int
  790. Xptitoken(tkp)
  791. Xregister struct token *tkp;
  792. X{
  793. X    register const char *cp;
  794. X    register int i, j, k;
  795. X
  796. X    if (!pttoken(tkp))
  797. X#ifdef DEBUG
  798. X        {
  799. X        VOID printf("EOF\n");
  800. X        return(0);
  801. X        }
  802. X#else
  803. X        return(0);
  804. X#endif    
  805. X    cp = tkp->tcp;
  806. X
  807. X#ifdef DEBUG
  808. X    VOID printf("Token: \"%.*s\" ", tkp->tcnt, cp);
  809. X#endif
  810. X
  811. X    if (tkp->tflg) {
  812. X        i = tkp->tcnt;
  813. X        if (*cp == '+' || *cp == '-') {
  814. X            cp++;
  815. X            i--;
  816. X        }
  817. X        while (0 <= --i) {
  818. X            j = tkp->tval.tnum*10;
  819. X            k = j + (*cp++ - '0');
  820. X            if (j/10 != tkp->tval.tnum  ||  k < j) {
  821. X                /* arithmetic overflow */
  822. X                tkp->tval.tnum = 1;
  823. X                return 0;
  824. X            }
  825. X            tkp->tval.tnum = k;
  826. X        }
  827. X    } else if (!(tkp->tval.ttmw  =  ptmatchstr(cp, tkp->tcnt, tmwords)))
  828. X      {
  829. X#ifdef DEBUG
  830. X        VOID printf("Not found!\n");
  831. X#endif
  832. X        tkp->tval.tnum = 1;
  833. X        return 0;
  834. X      }
  835. X
  836. X#ifdef DEBUG
  837. X    if(tkp->tflg)
  838. X        VOID printf("Val: %d.\n",tkp->tval.tnum);
  839. X    else VOID printf("Found: \"%s\", val: %d, type %d\n",
  840. X        tkp->tval.ttmw->went,tkp->tval.ttmw->wval,tkp->tval.ttmw->wtype);
  841. X#endif
  842. X
  843. X    return(1);
  844. X}
  845. X
  846. X/* Read token from input string into token structure */
  847. X    static int
  848. Xpttoken(tkp)
  849. Xregister struct token *tkp;
  850. X{
  851. X    register const char *cp;
  852. X    register int c;
  853. X    const char *astr;
  854. X
  855. X    tkp->tcp = astr = cp = tkp->tcp + tkp->tcnt;
  856. X    tkp->tbrkl = tkp->tbrk;        /* Set "last break" */
  857. X    tkp->tcnt = tkp->tbrk = tkp->tflg = 0;
  858. X    tkp->tval.tnum = 0;
  859. X
  860. X    while(c = *cp++)
  861. X      {    switch(c)
  862. X          {    case ' ': case '\t':    /* Flush all whitespace */
  863. X            case '\r': case '\n':
  864. X            case '\v': case '\f':
  865. X                if (!tkp->tcnt) {    /* If no token yet */
  866. X                    tkp->tcp = cp;    /* ignore the brk */
  867. X                    continue;    /* and go on. */
  868. X                }
  869. X                /* fall into */
  870. X            case '(': case ')':    /* Perhaps any non-alphanum */
  871. X            case '-': case ',':    /* shd qualify as break? */
  872. X            case '+':
  873. X            case '/': case ':': case '.':    /* Break chars */
  874. X                if(tkp->tcnt == 0)    /* If no token yet */
  875. X                  {    tkp->tcp = cp;    /* ignore the brk */
  876. X                    tkp->tbrkl = c;
  877. X                      continue;    /* and go on. */
  878. X                  }
  879. X                tkp->tbrk = c;
  880. X                return(tkp->tcnt);
  881. X          }
  882. X        if (!tkp->tcnt++) {        /* If first char of token, */
  883. X            if (isdigit(c)) {
  884. X                tkp->tflg = 1;
  885. X                if (astr<cp-2 && (cp[-2]=='-'||cp[-2]=='+')) {
  886. X                    /* timezone is break+sign+digit */
  887. X                    tkp->tcp--;
  888. X                    tkp->tcnt++;
  889. X                }
  890. X            }
  891. X        } else if ((isdigit(c)!=0) != tkp->tflg) { /* else check type */
  892. X            tkp->tbrk = c;
  893. X            return --tkp->tcnt;    /* Wrong type, back up */
  894. X        }
  895. X      }
  896. X    return(tkp->tcnt);        /* When hit EOF */
  897. X}
  898. X
  899. X
  900. X    static const struct tmwent *
  901. Xptmatchstr(astr,cnt,astruc)
  902. X    const char *astr;
  903. X    int cnt;
  904. X    const struct tmwent *astruc;
  905. X{
  906. X    register const char *cp, *mp;
  907. X    register int c;
  908. X    const struct tmwent *lastptr;
  909. X    int i;
  910. X
  911. X    lastptr = 0;
  912. X    for(;mp = astruc->went; astruc += 1)
  913. X      {    cp = astr;
  914. X        for(i = cnt; i > 0; i--)
  915. X          {
  916. X            switch (*cp++ - (c = *mp++))
  917. X              {    case 0: continue;    /* Exact match */
  918. X                case 'A'-'a':
  919. X                    if (ctab[c] == Letter)
  920. X                    continue;
  921. X              }
  922. X            break;
  923. X          }
  924. X        if(i==0)
  925. X            if (!*mp) return astruc;    /* Exact match */
  926. X            else if(lastptr) return(0);    /* Ambiguous */
  927. X            else lastptr = astruc;        /* 1st ambig */
  928. X      }
  929. X    return lastptr;
  930. X}
  931. END_OF_FILE
  932.   if test 19500 -ne `wc -c <'src/partime.c'`; then
  933.     echo shar: \"'src/partime.c'\" unpacked with wrong size!
  934.   fi
  935.   # end of 'src/partime.c'
  936. fi
  937. if test -f 'src/rcssyn.c' -a "${1}" != "-c" ; then 
  938.   echo shar: Will not clobber existing file \"'src/rcssyn.c'\"
  939. else
  940.   echo shar: Extracting \"'src/rcssyn.c'\" \(18364 characters\)
  941.   sed "s/^X//" >'src/rcssyn.c' <<'END_OF_FILE'
  942. X/*
  943. X *                     RCS file input
  944. X */
  945. X/*********************************************************************************
  946. X *                       Syntax Analysis.
  947. X *                       Keyword table
  948. X *                       Testprogram: define SYNTEST
  949. X *                       Compatibility with Release 2: define COMPAT2=1
  950. X *********************************************************************************
  951. X */
  952. X
  953. X/* Copyright (C) 1982, 1988, 1989 Walter Tichy
  954. X   Copyright 1990 by Paul Eggert
  955. X   Distributed under license by the Free Software Foundation, Inc.
  956. X
  957. XThis file is part of RCS.
  958. X
  959. XRCS is free software; you can redistribute it and/or modify
  960. Xit under the terms of the GNU General Public License as published by
  961. Xthe Free Software Foundation; either version 1, or (at your option)
  962. Xany later version.
  963. X
  964. XRCS is distributed in the hope that it will be useful,
  965. Xbut WITHOUT ANY WARRANTY; without even the implied warranty of
  966. XMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  967. XGNU General Public License for more details.
  968. X
  969. XYou should have received a copy of the GNU General Public License
  970. Xalong with RCS; see the file COPYING.  If not, write to
  971. Xthe Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  972. X
  973. XReport problems and direct all questions to:
  974. X
  975. X    rcs-bugs@cs.purdue.edu
  976. X
  977. X*/
  978. X
  979. X
  980. X/* $Log: rcssyn.c,v $
  981. X * Revision 5.4  1990/11/01  05:28:48  eggert
  982. X * When ignoring unknown phrases, copy them to the output RCS file.
  983. X * Permit arbitrary data in logs and comment leaders.
  984. X * Don't check for nontext on initial checkin.
  985. X *
  986. X * Revision 5.3  1990/09/20  07:58:32  eggert
  987. X * Remove the test for non-text bytes; it caused more pain than it cured.
  988. X *
  989. X * Revision 5.2  1990/09/04  08:02:30  eggert
  990. X * Parse RCS files with no revisions.
  991. X * Don't strip leading white space from diff commands.  Count RCS lines better.
  992. X *
  993. X * Revision 5.1  1990/08/29  07:14:06  eggert
  994. X * Add -kkvl.  Clean old log messages too.
  995. X *
  996. X * Revision 5.0  1990/08/22  08:13:44  eggert
  997. X * Try to parse future RCS formats without barfing.
  998. X * Add -k.  Don't require final newline.
  999. X * Remove compile-time limits; use malloc instead.
  1000. X * Don't output branch keyword if there's no default branch,
  1001. X * because RCS version 3 doesn't understand it.
  1002. X * Tune.  Remove lint.
  1003. X * Add support for ISO 8859.  Ansify and Posixate.
  1004. X * Check that a newly checked-in file is acceptable as input to 'diff'.
  1005. X * Check diff's output.
  1006. X *
  1007. X * Revision 4.6  89/05/01  15:13:32  narten
  1008. X * changed copyright header to reflect current distribution rules
  1009. X * 
  1010. X * Revision 4.5  88/08/09  19:13:21  eggert
  1011. X * Allow cc -R; remove lint.
  1012. X * 
  1013. X * Revision 4.4  87/12/18  11:46:16  narten
  1014. X * more lint cleanups (Guy Harris)
  1015. X * 
  1016. X * Revision 4.3  87/10/18  10:39:36  narten
  1017. X * Updating version numbers. Changes relative to 1.1 actually relative to
  1018. X * 4.1
  1019. X * 
  1020. X * Revision 1.3  87/09/24  14:00:49  narten
  1021. X * Sources now pass through lint (if you ignore printf/sprintf/fprintf 
  1022. X * warnings)
  1023. X * 
  1024. X * Revision 1.2  87/03/27  14:22:40  jenkins
  1025. X * Port to suns
  1026. X * 
  1027. X * Revision 4.1  83/03/28  11:38:49  wft
  1028. X * Added parsing and printing of default branch.
  1029. X * 
  1030. X * Revision 3.6  83/01/15  17:46:50  wft
  1031. X * Changed readdelta() to initialize selector and log-pointer.
  1032. X * Changed puttree to check for selector==DELETE; putdtext() uses DELNUMFORM.
  1033. X *
  1034. X * Revision 3.5  82/12/08  21:58:58  wft
  1035. X * renamed Commentleader to Commleader.
  1036. X *
  1037. X * Revision 3.4  82/12/04  13:24:40  wft
  1038. X * Added routine gettree(), which updates keeplock after reading the
  1039. X * delta tree.
  1040. X *
  1041. X * Revision 3.3  82/11/28  21:30:11  wft
  1042. X * Reading and printing of Suffix removed; version COMPAT2 skips the
  1043. X * Suffix for files of release 2 format. Fixed problems with printing nil.
  1044. X *
  1045. X * Revision 3.2  82/10/18  21:18:25  wft
  1046. X * renamed putdeltatext to putdtext.
  1047. X *
  1048. X * Revision 3.1  82/10/11  19:45:11  wft
  1049. X * made sure getc() returns into an integer.
  1050. X */
  1051. X
  1052. X
  1053. X
  1054. X/* version COMPAT2 reads files of the format of release 2 and 3, but
  1055. X * generates files of release 3 format. Need not be defined if no
  1056. X * old RCS files generated with release 2 exist.
  1057. X */
  1058. X/* version SYNTEST inputs a RCS file and then prints out its internal
  1059. X * data structures.
  1060. X*/
  1061. X
  1062. X#include "rcsbase.h"
  1063. X
  1064. XlibId(synId, "$Id: rcssyn.c,v 5.4 1990/11/01 05:28:48 eggert Exp $")
  1065. X
  1066. X/* forward */
  1067. Xstatic const char *getkeyval P((const char*,enum tokens,int));
  1068. X
  1069. X/* keyword table */
  1070. X
  1071. Xconst char
  1072. X    Kdesc[]     = "desc",
  1073. X    Klog[]      = "log",
  1074. X    Ktext[]     = "text";
  1075. X
  1076. Xstatic const char
  1077. X    Kaccess[]   = "access",
  1078. X    Kauthor[]   = "author",
  1079. X    Kbranch[]   = "branch",
  1080. X    Kbranches[] = "branches",
  1081. X    Kcomment[]  = "comment",
  1082. X    Kdate[]     = "date",
  1083. X    Kexpand[]   = "expand",
  1084. X    Khead[]     = "head",
  1085. X    Klocks[]    = "locks",
  1086. X    Knext[]     = "next",
  1087. X    Kstate[]    = "state",
  1088. X    Kstrict[]   = "strict",
  1089. X#if COMPAT2
  1090. X    Ksuffix[]   = "suffix",
  1091. X#endif
  1092. X    Ksymbols[]  = "symbols";
  1093. X
  1094. Xstatic struct buf Commleader;
  1095. Xstatic struct cbuf Ignored;
  1096. Xstruct cbuf Comment;
  1097. Xstruct access   * AccessList;
  1098. Xstruct assoc    * Symbols;
  1099. Xstruct lock     * Locks;
  1100. Xint          Expand;
  1101. Xint               StrictLocks;
  1102. Xstruct hshentry * Head;
  1103. Xconst char      * Dbranch;
  1104. Xint               TotalDeltas;
  1105. X
  1106. X
  1107. X    static void
  1108. Xgetsemi(key)
  1109. X    const char *key;
  1110. X/* Get a semicolon to finish off a phrase started by KEY.  */
  1111. X{
  1112. X    if (!getlex(SEMI))
  1113. X        fatserror("missing ';' after '%s'", key);
  1114. X}
  1115. X
  1116. X    static struct hshentry *
  1117. Xgetdnum()
  1118. X/* Get a delta number.  */
  1119. X{
  1120. X    register struct hshentry *delta = getnum();
  1121. X    if (delta && countnumflds(delta->num)&1)
  1122. X        fatserror("%s isn't a delta number", delta->num);
  1123. X    return delta;
  1124. X}
  1125. X
  1126. X
  1127. X    void
  1128. Xgetadmin()
  1129. X/* Read an <admin> and initialize the appropriate global variables.  */
  1130. X{
  1131. X    register const char *id;
  1132. X        struct access   * newaccess;
  1133. X        struct assoc    * newassoc;
  1134. X        struct lock     * newlock;
  1135. X        struct hshentry * delta;
  1136. X    struct access **LastAccess;
  1137. X    struct assoc **LastSymbol;
  1138. X    struct lock **LastLock;
  1139. X    struct buf b;
  1140. X    struct cbuf cb;
  1141. X
  1142. X        TotalDeltas=0;
  1143. X
  1144. X    getkey(Khead);
  1145. X    Head = getdnum();
  1146. X    getsemi(Khead);
  1147. X
  1148. X    Dbranch = nil;
  1149. X    if (getkeyopt(Kbranch)) {
  1150. X        if ((delta = getnum()))
  1151. X            Dbranch = delta->num;
  1152. X        getsemi(Kbranch);
  1153. X        }
  1154. X
  1155. X
  1156. X#if COMPAT2
  1157. X        /* read suffix. Only in release 2 format */
  1158. X    if (getkeyopt(Ksuffix)) {
  1159. X                if (nexttok==STRING) {
  1160. X            readstring(); nextlex(); /* Throw away the suffix.  */
  1161. X        } else if (nexttok==ID) {
  1162. X                        nextlex();
  1163. X                }
  1164. X        getsemi(Ksuffix);
  1165. X        }
  1166. X#endif
  1167. X
  1168. X    getkey(Kaccess);
  1169. X    LastAccess = &AccessList;
  1170. X        while (id=getid()) {
  1171. X        newaccess = ftalloc(struct access);
  1172. X                newaccess->login = id;
  1173. X        *LastAccess = newaccess;
  1174. X        LastAccess = &newaccess->nextaccess;
  1175. X        }
  1176. X    *LastAccess = nil;
  1177. X    getsemi(Kaccess);
  1178. X
  1179. X    getkey(Ksymbols);
  1180. X    LastSymbol = &Symbols;
  1181. X        while (id = getid()) {
  1182. X                if (!getlex(COLON))
  1183. X            fatserror("missing ':' in symbolic name definition");
  1184. X                if (!(delta=getnum())) {
  1185. X            fatserror("missing number in symbolic name definition");
  1186. X                } else { /*add new pair to association list*/
  1187. X            newassoc = ftalloc(struct assoc);
  1188. X                        newassoc->symbol=id;
  1189. X            newassoc->num = delta->num;
  1190. X            *LastSymbol = newassoc;
  1191. X            LastSymbol = &newassoc->nextassoc;
  1192. X                }
  1193. X        }
  1194. X    *LastSymbol = nil;
  1195. X    getsemi(Ksymbols);
  1196. X
  1197. X    getkey(Klocks);
  1198. X    LastLock = &Locks;
  1199. X        while (id = getid()) {
  1200. X                if (!getlex(COLON))
  1201. X            fatserror("missing ':' in lock");
  1202. X        if (!(delta=getdnum())) {
  1203. X            fatserror("missing number in lock");
  1204. X                } else { /*add new pair to lock list*/
  1205. X            newlock = ftalloc(struct lock);
  1206. X                        newlock->login=id;
  1207. X                        newlock->delta=delta;
  1208. X            *LastLock = newlock;
  1209. X            LastLock = &newlock->nextlock;
  1210. X                }
  1211. X        }
  1212. X    *LastLock = nil;
  1213. X    getsemi(Klocks);
  1214. X
  1215. X    if ((StrictLocks = getkeyopt(Kstrict)))
  1216. X        getsemi(Kstrict);
  1217. X
  1218. X    Comment.size = 0;
  1219. X    if (getkeyopt(Kcomment)) {
  1220. X        if (nexttok==STRING) {
  1221. X            Comment = savestring(&Commleader);
  1222. X            nextlex();
  1223. X        }
  1224. X        getsemi(Kcomment);
  1225. X        }
  1226. X
  1227. X    Expand = KEYVAL_EXPAND;
  1228. X    if (getkeyopt(Kexpand)) {
  1229. X        if (nexttok==STRING) {
  1230. X            bufautobegin(&b);
  1231. X            cb = savestring(&b);
  1232. X            if ((Expand = str2expmode(cb.string)) < 0)
  1233. X                fatserror("unknown expand mode %s", b.string);
  1234. X            bufautoend(&b);
  1235. X            nextlex();
  1236. X        }
  1237. X        getsemi(Kexpand);
  1238. X        }
  1239. X    Ignored = getphrases(Kdesc);
  1240. X}
  1241. X
  1242. Xconst char *const expand_names[] = {
  1243. X    /* These must agree with *_EXPAND in rcsbase.h.  */
  1244. X    "kv","kvl","k","v","o",
  1245. X    0
  1246. X};
  1247. X
  1248. X    int
  1249. Xstr2expmode(s)
  1250. X    const char *s;
  1251. X/* Yield expand mode corresponding to S, or -1 if bad.  */
  1252. X{
  1253. X    const char *const *p;
  1254. X
  1255. X    for (p = expand_names;  *p;  ++p)
  1256. X        if (strcmp(*p,s) == 0)
  1257. X            return p - expand_names;
  1258. X    return -1;
  1259. X}
  1260. X
  1261. X
  1262. X    void
  1263. Xignorephrase()
  1264. X/* Ignore a phrase introduced by a later version of RCS.  */
  1265. X{
  1266. X    warnignore();
  1267. X    hshenter=false;
  1268. X    for (;;) {
  1269. X        switch (nexttok) {
  1270. X        case SEMI: hshenter=true; nextlex(); return;
  1271. X        case ID:
  1272. X        case NUM: ffree1(NextString); break;
  1273. X        case STRING: readstring(); break;
  1274. X        default: break;
  1275. X        }
  1276. X        nextlex();
  1277. X    }
  1278. X}
  1279. X
  1280. X
  1281. X    static int
  1282. Xgetdelta()
  1283. X/* Function: reads a delta block.
  1284. X * returns false if the current block does not start with a number.
  1285. X */
  1286. X{
  1287. X        register struct hshentry * Delta, * num;
  1288. X    struct branchhead **LastBranch, *NewBranch;
  1289. X
  1290. X    if (!(Delta = getdnum()))
  1291. X        return false;
  1292. X
  1293. X        hshenter = false; /*Don't enter dates into hashtable*/
  1294. X        Delta->date = getkeyval(Kdate, NUM, false);
  1295. X        hshenter=true;    /*reset hshenter for revision numbers.*/
  1296. X
  1297. X        Delta->author = getkeyval(Kauthor, ID, false);
  1298. X
  1299. X        Delta->state = getkeyval(Kstate, ID, true);
  1300. X
  1301. X    getkey(Kbranches);
  1302. X    LastBranch = &Delta->branches;
  1303. X    while ((num = getdnum())) {
  1304. X        NewBranch = ftalloc(struct branchhead);
  1305. X                NewBranch->hsh = num;
  1306. X        *LastBranch = NewBranch;
  1307. X        LastBranch = &NewBranch->nextbranch;
  1308. X        }
  1309. X    *LastBranch = nil;
  1310. X    getsemi(Kbranches);
  1311. X
  1312. X    getkey(Knext);
  1313. X    Delta->next = num = getdnum();
  1314. X    getsemi(Knext);
  1315. X    Delta->lockedby = nil;
  1316. X    Delta->selector = true;
  1317. X    Delta->ig = getphrases(Kdesc);
  1318. X        TotalDeltas++;
  1319. X        return (true);
  1320. X}
  1321. X
  1322. X
  1323. X    void
  1324. Xgettree()
  1325. X/* Function: Reads in the delta tree with getdelta(), then
  1326. X * updates the lockedby fields.
  1327. X */
  1328. X{
  1329. X    const struct lock *currlock;
  1330. X
  1331. X        while (getdelta());
  1332. X        currlock=Locks;
  1333. X        while (currlock) {
  1334. X                currlock->delta->lockedby = currlock->login;
  1335. X                currlock = currlock->nextlock;
  1336. X        }
  1337. X}
  1338. X
  1339. X
  1340. X    void
  1341. Xgetdesc(prdesc)
  1342. Xint  prdesc;
  1343. X/* Function: read in descriptive text
  1344. X * nexttok is not advanced afterwards.
  1345. X * If prdesc is set, the text is printed to stdout.
  1346. X */
  1347. X{
  1348. X
  1349. X    getkeystring(Kdesc);
  1350. X        if (prdesc)
  1351. X                printstring();  /*echo string*/
  1352. X        else    readstring();   /*skip string*/
  1353. X}
  1354. X
  1355. X
  1356. X
  1357. X
  1358. X
  1359. X
  1360. X    static const char *
  1361. Xgetkeyval(keyword, token, optional)
  1362. X    const char *keyword;
  1363. X    enum tokens token;
  1364. X    int optional;
  1365. X/* reads a pair of the form
  1366. X * <keyword> <token> ;
  1367. X * where token is one of <id> or <num>. optional indicates whether
  1368. X * <token> is optional. A pointer to
  1369. X * the actual character string of <id> or <num> is returned.
  1370. X */
  1371. X{
  1372. X    register const char *val = nil;
  1373. X
  1374. X    getkey(keyword);
  1375. X        if (nexttok==token) {
  1376. X                val = NextString;
  1377. X                nextlex();
  1378. X        } else {
  1379. X        if (!optional)
  1380. X            fatserror("missing %s", keyword);
  1381. X        }
  1382. X    getsemi(keyword);
  1383. X        return(val);
  1384. X}
  1385. X
  1386. X
  1387. X
  1388. X
  1389. X    void
  1390. Xputadmin(fout)
  1391. Xregister FILE * fout;
  1392. X/* Function: Print the <admin> node read with getadmin() to file fout.
  1393. X * Assumption: Variables AccessList, Symbols, Locks, StrictLocks,
  1394. X * and Head have been set.
  1395. X */
  1396. X{
  1397. X    const struct assoc *curassoc;
  1398. X    const struct lock *curlock;
  1399. X    const struct access *curaccess;
  1400. X    register const char *sp;
  1401. X    register size_t ss;
  1402. X
  1403. X    aprintf(fout, "%s\t%s;\n", Khead, Head?Head->num:"");
  1404. X    if (Dbranch && VERSION(4)<=RCSversion)
  1405. X        aprintf(fout, "%s\t%s;\n", Kbranch, Dbranch);
  1406. X
  1407. X    aputs(Kaccess, fout);
  1408. X        curaccess = AccessList;
  1409. X        while (curaccess) {
  1410. X           aprintf(fout, "\n\t%s", curaccess->login);
  1411. X               curaccess = curaccess->nextaccess;
  1412. X        }
  1413. X    aprintf(fout, ";\n%s", Ksymbols);
  1414. X        curassoc = Symbols;
  1415. X        while (curassoc) {
  1416. X           aprintf(fout, "\n\t%s:%s", curassoc->symbol, curassoc->num);
  1417. X               curassoc = curassoc->nextassoc;
  1418. X        }
  1419. X    aprintf(fout, ";\n%s", Klocks);
  1420. X        curlock = Locks;
  1421. X        while (curlock) {
  1422. X           aprintf(fout, "\n\t%s:%s", curlock->login, curlock->delta->num);
  1423. X               curlock = curlock->nextlock;
  1424. X        }
  1425. X    if (StrictLocks) aprintf(fout, "; %s", Kstrict);
  1426. X    aprintf(fout, ";\n");
  1427. X    if ((ss = Comment.size)) {
  1428. X        aprintf(fout, "%s\t%c", Kcomment, SDELIM);
  1429. X        sp = Comment.string;
  1430. X        do {
  1431. X            if (*sp == SDELIM)
  1432. X            afputc(SDELIM,fout);
  1433. X            afputc(*sp++,fout);
  1434. X        } while (--ss);
  1435. X        aprintf(fout, "%c;\n", SDELIM);
  1436. X        }
  1437. X    if (Expand != KEYVAL_EXPAND)
  1438. X        aprintf(fout, "%s\t%c%s%c;\n",
  1439. X            Kexpand, SDELIM, expand_names[Expand], SDELIM
  1440. X        );
  1441. X    awrite(Ignored.string, Ignored.size, fout);
  1442. X    aputc('\n', fout);
  1443. X}
  1444. X
  1445. X
  1446. X
  1447. X
  1448. X    static void
  1449. Xputdelta(node,fout)
  1450. Xregister const struct hshentry *node;
  1451. Xregister FILE * fout;
  1452. X/* Function: prints a <delta> node to fout;
  1453. X */
  1454. X{
  1455. X    const struct branchhead *nextbranch;
  1456. X
  1457. X        if (node == nil) return;
  1458. X
  1459. X    aprintf(fout, "\n%s\n%s\t%s;\t%s %s;\t%s %s;\nbranches",
  1460. X        node->num,
  1461. X        Kdate, node->date,
  1462. X        Kauthor, node->author,
  1463. X        Kstate, node->state?node->state:""
  1464. X    );
  1465. X        nextbranch = node->branches;
  1466. X        while (nextbranch) {
  1467. X           aprintf(fout, "\n\t%s", nextbranch->hsh->num);
  1468. X               nextbranch = nextbranch->nextbranch;
  1469. X        }
  1470. X
  1471. X    aprintf(fout, ";\n%s\t%s;\n", Knext, node->next?node->next->num:"");
  1472. X    awrite(node->ig.string, node->ig.size, fout);
  1473. X}
  1474. X
  1475. X
  1476. X
  1477. X
  1478. X    void
  1479. Xputtree(root,fout)
  1480. Xconst struct hshentry * root;
  1481. Xregister FILE * fout;
  1482. X/* Function: prints the delta tree in preorder to fout, starting with root.
  1483. X */
  1484. X{
  1485. X    const struct branchhead *nextbranch;
  1486. X
  1487. X        if (root==nil) return;
  1488. X
  1489. X    if (root->selector)
  1490. X        putdelta(root,fout);
  1491. X
  1492. X        puttree(root->next,fout);
  1493. X
  1494. X        nextbranch = root->branches;
  1495. X        while (nextbranch) {
  1496. X             puttree(nextbranch->hsh,fout);
  1497. X             nextbranch = nextbranch->nextbranch;
  1498. X        }
  1499. X}
  1500. X
  1501. X
  1502. X
  1503. Xint putdtext(num,log,srcfilename,fout,diffmt)
  1504. X    const char *num, *srcfilename;
  1505. X    struct cbuf log;
  1506. X    FILE *fout;
  1507. X    int diffmt;
  1508. X/* Function: write a deltatext-node to fout.
  1509. X * num points to the deltanumber, log to the logmessage, and
  1510. X * sourcefile contains the text. Doubles up all SDELIMs in both the
  1511. X * log and the text; Makes sure the log message ends in \n.
  1512. X * returns false on error.
  1513. X * If diffmt is true, also checks that text is valid diff -n output.
  1514. X */
  1515. X{
  1516. X    FILE *fin;
  1517. X    int result;
  1518. X    if (!(fin = fopen(srcfilename,"r"))) {
  1519. X        eerror(srcfilename);
  1520. X        return false;
  1521. X    }
  1522. X    result = putdftext(num,log,fin,fout,diffmt);
  1523. X    ffclose(fin);
  1524. X    return result;
  1525. X}
  1526. X
  1527. X    int
  1528. Xputdftext(num,log,fin,fout,diffmt)
  1529. X    const char *num;
  1530. X    struct cbuf log;
  1531. X    register FILE *fin;
  1532. X    register FILE *fout;
  1533. X    int diffmt;
  1534. X/* like putdtext(), except the source file is already open */
  1535. X{
  1536. X    register const char *sp;
  1537. X    register int c;
  1538. X    register size_t ss;
  1539. X    int ed;
  1540. X    struct diffcmd dc;
  1541. X
  1542. X    aprintf(fout,DELNUMFORM,num,Klog);
  1543. X        /* put log */
  1544. X    afputc(SDELIM,fout);
  1545. X    sp = log.string;
  1546. X    for (ss = log.size;  ss;  --ss) {
  1547. X        if (*sp == SDELIM)
  1548. X            aputc(SDELIM,fout);
  1549. X        aputc(*sp++,fout);
  1550. X    }
  1551. X        /* put text */
  1552. X    aprintf(fout, "\n%c\n%s\n%c",SDELIM,Ktext,SDELIM);
  1553. X    if (!diffmt) {
  1554. X        /* Copy the file */
  1555. X        while ((c=getc(fin))!=EOF) {
  1556. X        if (c==SDELIM) aputc(SDELIM,fout);   /*double up SDELIM*/
  1557. X        aputc(c,fout);
  1558. X        }
  1559. X    } else {
  1560. X        initdiffcmd(&dc);
  1561. X        while (0  <=  (ed = getdiffcmd(fin,EOF,fout,&dc)))
  1562. X        if (ed)
  1563. X            while (dc.nlines--)
  1564. X            do {
  1565. X                if ((c=getc(fin)) == EOF) {
  1566. X                if (!dc.nlines)
  1567. X                    goto OK_EOF;
  1568. X                faterror("unexpected EOF in diff output");
  1569. X                }
  1570. X                if (c==SDELIM) aputc(SDELIM,fout);
  1571. X                aputc(c,fout);
  1572. X            } while (c != '\n');
  1573. X    }
  1574. X    OK_EOF:
  1575. X    aprintf(fout, "%c\n", SDELIM);
  1576. X    return true;
  1577. X}
  1578. X
  1579. X    void
  1580. Xinitdiffcmd(dc)
  1581. X    register struct diffcmd *dc;
  1582. X/* Initialize *dc suitably for getdiffcmd(). */
  1583. X{
  1584. X    dc->adprev = 0;
  1585. X    dc->dafter = 0;
  1586. X}
  1587. X
  1588. X    int
  1589. Xgetdiffcmd(fin,delimiter,fout,dc)
  1590. X    register FILE *fin, *fout;
  1591. X    int delimiter;
  1592. X    struct diffcmd *dc;
  1593. X/* Get a editing command output by 'diff -n' from fin.
  1594. X * The input is delimited by the delimiter, which may be EOF for no delimiter.
  1595. X * Copy a clean version of the command to fout (if nonnull).
  1596. X * Yield 0 for 'd', 1 for 'a', and -1 for EOF.
  1597. X * Store the command's line number and length into dc->line1 and dc->nlines.
  1598. X * Keep dc->adprev and dc->dafter up to date.
  1599. X */
  1600. X{
  1601. X    register int c;
  1602. X    register char *p;
  1603. X    unsigned long line1, nlines;
  1604. X    char buf[BUFSIZ];
  1605. X    c = getc(fin);
  1606. X    if (c==delimiter) {
  1607. X        if (c!=EOF && fout)
  1608. X            aputc(c, fout);
  1609. X        return EOF;
  1610. X    }
  1611. X    p = buf;
  1612. X    do {
  1613. X        if (c == EOF) {
  1614. X            faterror("unexpected EOF in diff output");
  1615. X        }
  1616. X        if (buf+BUFSIZ-2 <= p) {
  1617. X            faterror("diff output command line too long");
  1618. X        }
  1619. X        *p++ = c;
  1620. X    } while ((c=getc(fin)) != '\n');
  1621. X    if (delimiter!=EOF)
  1622. X        ++rcsline;
  1623. X    *p = '\0';
  1624. X    for (p = buf+1;  *p++ == ' ';)
  1625. X        ;
  1626. X    --p;
  1627. X    if (!((buf[0]=='a' || buf[0]=='d')  &&  isdigit(*p))) {
  1628. X        faterror("bad diff output: %s", buf);
  1629. X    }
  1630. X    line1 = 0;
  1631. X    do {
  1632. X        line1 = line1*10 + (*p++ - '0');
  1633. X    } while (isdigit(*p));
  1634. X    while (*p++ == ' ')
  1635. X        ;
  1636. X    --p;
  1637. X    nlines = 0;
  1638. X    while (isdigit(*p))
  1639. X        nlines = nlines*10 + (*p++ - '0');
  1640. X    if (!nlines) {
  1641. X        faterror("incorrect range %lu in diff output: %s", nlines, buf);
  1642. X    }
  1643. X    switch (buf[0]) {
  1644. X        case 'a':
  1645. X        if (line1 < dc->adprev) {
  1646. X            faterror("backward insertion in diff output: %s", buf);
  1647. X        }
  1648. X        dc->adprev = line1 + 1;
  1649. X        break;
  1650. X        case 'd':
  1651. X        if (line1 < dc->adprev  ||  line1 < dc->dafter) {
  1652. X            faterror("backward deletion in diff output: %s", buf);
  1653. X        }
  1654. X        dc->adprev = line1;
  1655. X        dc->dafter = line1 + nlines;
  1656. X        break;
  1657. X    }
  1658. X    if (fout) {
  1659. X        aprintf(fout, "%s\n", buf);
  1660. X    }
  1661. X    dc->line1 = line1;
  1662. X    dc->nlines = nlines;
  1663. X    return buf[0] == 'a';
  1664. X}
  1665. X
  1666. X
  1667. X
  1668. X#ifdef SYNTEST
  1669. X
  1670. Xconst char cmdid[] = "syntest";
  1671. X
  1672. X    int
  1673. Xmain(argc,argv)
  1674. Xint argc; char * argv[];
  1675. X{
  1676. X
  1677. X        if (argc<2) {
  1678. X        aputs("No input file\n",stderr);
  1679. X        exitmain(EXIT_FAILURE);
  1680. X        }
  1681. X        if ((finptr=fopen(argv[1], "r")) == NULL) {
  1682. X        faterror("can't open input file %s", argv[1]);
  1683. X        }
  1684. X        Lexinit();
  1685. X        getadmin();
  1686. X        putadmin(stdout);
  1687. X
  1688. X        gettree();
  1689. X        puttree(Head,stdout);
  1690. X
  1691. X        getdesc(true);
  1692. X
  1693. X        if (nextlex(),nexttok!=EOFILE) {
  1694. X        fatserror("expecting EOF");
  1695. X        }
  1696. X    exitmain(EXIT_SUCCESS);
  1697. X}
  1698. X
  1699. X
  1700. Xexiting void exiterr() { _exit(EXIT_FAILURE); }
  1701. X
  1702. X
  1703. X#endif
  1704. X
  1705. END_OF_FILE
  1706.   if test 18364 -ne `wc -c <'src/rcssyn.c'`; then
  1707.     echo shar: \"'src/rcssyn.c'\" unpacked with wrong size!
  1708.   fi
  1709.   # end of 'src/rcssyn.c'
  1710. fi
  1711. echo shar: End of archive 8 \(of 12\).
  1712. cp /dev/null ark8isdone
  1713. MISSING=""
  1714. for I in 1 2 3 4 5 6 7 8 9 10 11 12 ; do
  1715.     if test ! -f ark${I}isdone ; then
  1716.     MISSING="${MISSING} ${I}"
  1717.     fi
  1718. done
  1719. if test "${MISSING}" = "" ; then
  1720.     echo You have unpacked all 12 archives.
  1721.     rm -f ark[1-9]isdone ark[1-9][0-9]isdone
  1722. else
  1723.     echo You still must unpack the following archives:
  1724.     echo "        " ${MISSING}
  1725. fi
  1726. exit 0
  1727. exit 0 # Just in case...
  1728.